from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys

# Pyqt5 Python37
# 20210509
# 滚动条控件用法
# 此控件效果形似Slider控件
# 使用三个滚动条调整label中字色


class QSample(QWidget):
    def __init__(self):
        super(QSample, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('QSample')
        self.resize(400, 300)

        # 展示效果容器
        self.label = QLabel('Sample Text')
        self.label.setAlignment(Qt.AlignCenter)

        # 定义三个滚动条，最大值255
        self.scroll1 = QScrollBar()
        self.scroll1.setMaximum(255)
        self.scroll1.sliderMoved.connect(self.slider)
        self.scroll2 = QScrollBar()
        self.scroll2.setMaximum(255)
        self.scroll2.sliderMoved.connect(self.slider)
        self.scroll3 = QScrollBar()
        self.scroll3.setMaximum(255)
        self.scroll3.sliderMoved.connect(self.slider)

        # 滚动条水平布局
        sliderLayout = QHBoxLayout()
        sliderLayout.addWidget(self.scroll1)
        sliderLayout.addWidget(self.scroll2)
        sliderLayout.addWidget(self.scroll3)

        # 主窗口水平布局
        mainlayout = QHBoxLayout()
        mainlayout.addWidget(self.label)
        mainlayout.addLayout(sliderLayout)

        self.setLayout(mainlayout)

    # 滚动条响应
    def slider(self):
        palette = QPalette()  # 使用palette控制字色
        # 取三个滚动条值定义QColor色值
        c = QColor(self.scroll1.value(),
                   self.scroll2.value(), self.scroll3.value())
        palette.setColor(QPalette.Foreground, c)
        self.label.setPalette(palette)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QSample()
    main.show()
    sys.exit(app.exec_())